<%@ page language="java" contentType="text/html; charset=UTF-8"
		 pageEncoding="UTF-8"%>
<!--_meta 作为公共模版分离出去-->
<!DOCTYPE HTML>
<html>
<head>
	<%@ include file= "_meta.jsp"%>
	<link title="style1" rel="stylesheet" href="${pageContext.request.contextPath}/css/add_course.css" type="text/css" />
</head>
<body>

<%@ include file= "_menu.jsp"%>
<%@ include file= "_header.jsp"%>
<div class="form_content">
	<div id="test">

		<fieldset>
			<legend>录入课程</legend>
			<div class="form-row">
				<div class="field-label"><label for="cname">课程名称</label>:</div>
				<div class="field-widget"><input name="cname" id="cname" class="required" title="Enter your name"/>
				</div>
			</div>

			<div class="form-row">
				<div class="field-label"><label for="credit">学分</label>:</div>
				<div class="field-widget"><input name="credit" id="credit" class="required validate-email"
												 title="Enter your name"/></div>
			</div>

			<div class="form-row">
				<div class="field-label"><label for="teacher">教师</label>:</div>
				<div class="field-widget">
					<select id="teacher" name="teacher" class="validate-selection" title="Choose your department">
						<c:forEach var="student" items="${teachers}" varStatus="trow">
							<option value="${student.tname}" tid="${student.tid}">${student.tname}</option>
						</c:forEach>
					</select>
				</div>
			</div>
			<div class="form-row">
				<div class="field-label"><label for="major">专业</label>:</div>
				<div class="field-widget">
					<select id="major" name="major" class="validate-selection" title="Choose your department">
						<c:forEach var="major" items="${majors}" varStatus="trow">
							<option value="${major.major_name}"
									major_id="${major.major_id}">${major.major_name}</option>
						</c:forEach>
					</select>
				</div>
			</div>

			<div class="form-row">
				<div class="field-label"><label for="chour">总课时</label>:</div>
				<div class="field-widget"><input name="chour" id="chour" class="required validate-password"
												 title="Enter a password greater than 6 characters"/></div>
			</div>

			<div class="form-row">
				<div class="field-label"><label for="max_people">最大选课人数</label>:</div>
				<div class="field-widget"><input name="max_people" id="max_people"
												 class="required validate-password-confirm"
												 title="Enter the same password for confirmation"/></div>
			</div>
		</fieldset>

		<input type="submit" class="submit" value="提交"/> <input class="reset" type="button" value="重置"
																onclick="valid.reset(); return false"/>
	</div>
</div>
<%@ include file="_footer.jsp"%>
<script type="text/javascript">
    (function () {
        function sendReq() {
            var msg = {};
            var cname = $('#cname').val();
            var credit = $('#credit').val();
            var tid = $('#teacher option:selected').attr('tid');
            var major_id = $('#major option:selected').attr('major_id');
            var chour = $('#chour').val();
            var max_people = $('#max_people').val();
            msg.cname = cname;
            msg.credit = credit;
            msg.tid = tid;
            msg.major_id = major_id;
            msg.chour = chour;
            msg.max_people = max_people;
            console.log(msg);
            $.ajax({
                url: '${pageContext.request.contextPath}/admin/add_course',
                data: msg,
                dataType: "text",
                success: function (data) {
                    if (data == "success") {
                        alert("添加成功!")
                    }
                    else {
                        alert('添加失败!')
                    }
                }
            })
        }

        $('.submit').click(sendReq);
    })()
    /*function formCallback(result, form) {
        window.status = "valiation callback for form '" + form.id + "': result = " + result;
    }

    var valid = new Validation('test', {immediate : true, onFormValidate : formCallback});
    Validation.addAllThese([
        ['validate-password', '> 6 characters', {
            minLength : 7,
            notOneOf : ['password','PASSWORD','1234567','0123456'],
            notEqualToField : 'field1'
        }],
        ['validate-password-confirm', 'please try again.', {
            equalToField : 'field8'
        }]
    ]);*/
</script>
</body>
</html>